package com.zhkc.wisdom.common.web.desensitization;


import org.apache.commons.lang3.StringUtils;

/**
 * .
 *
 * @author kehong liu .
 */
public final class DesensitizationUtils {

	private DesensitizationUtils() {
	}

	public static String idCardNum(String id) {
		if (StringUtils.isBlank(id)) {
			return "";
		}
		return StringUtils.left(id, 6).concat(StringUtils
				.removeStart(StringUtils.leftPad(StringUtils.right(id, 4), StringUtils.length(id), "*"), "******"));
	}

	public static String mobilePhone(String num) {
		if (StringUtils.isBlank(num)) {
			return "";
		}
		return StringUtils.left(num, 3).concat(StringUtils
				.removeStart(StringUtils.leftPad(StringUtils.right(num, 4), StringUtils.length(num), "*"), "***"));
	}

	public static String address(String address, int sensitiveSize) {
		if (StringUtils.isBlank(address)) {
			return "";
		}
		int length = StringUtils.length(address);
		return StringUtils.rightPad(StringUtils.left(address, length - sensitiveSize), length, "*");
	}

	public static String email(String email) {
		if (StringUtils.isBlank(email)) {
			return "";
		}
		int index = StringUtils.indexOf(email, "@");
		if (index <= 1) {
			return email;
		}
		else {
			return StringUtils.rightPad(StringUtils.left(email, 3), index, "*")
					.concat(StringUtils.mid(email, index, StringUtils.length(email)));
		}
	}

	public static String bankCard(String cardNum) {
		if (StringUtils.isBlank(cardNum)) {
			return "";
		}
		return StringUtils.left(cardNum, 6).concat(StringUtils.removeStart(
				StringUtils.leftPad(StringUtils.right(cardNum, 4), StringUtils.length(cardNum), "*"), "******"));
	}
}
